package com.bookmarket.controller;

import com.bookmarket.entity.Accident;
import com.bookmarket.entity.Content;
import com.bookmarket.service.LQReturnOrderService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 退货记录表
 *      用于显示退货记录及新增退货记录
 */
@RestController
@RequestMapping("/returnOrder")
public class LQ_ReturnOrderController {

    @Resource
    private LQReturnOrderService returnOrderService;

    /**
     * 查询聊天历史，通过发送人与接收人的ID
     */
    @RequestMapping("/history")
    public ModelAndView queryAllContent(int adminId,int customId){
        ModelAndView mv = new ModelAndView();
        mv.setView(new MappingJackson2JsonView());
        List<Content> list = returnOrderService.queryAllContent(adminId,customId);
        mv.addObject("list",list);
        return mv;
    }

    /**
     * 拉取好友列表，通过历史记录中与发送人有过发送记录的
     */
    @RequestMapping("/friends")
    public ModelAndView queryAllFriends(int id){
        ModelAndView mv = new ModelAndView();
        mv.setView(new MappingJackson2JsonView());
        List<Content> list = returnOrderService.queryAllFriends(id);
        mv.addObject("list",list);
        return mv;
    }

    /**
     * 获取退款记录表，分页，查询
     */
    @RequestMapping("/queryAccident")
    public Map queryAccident(int currentPage,int pageSize,Accident accident){
        Page page = returnOrderService.queryAccident(currentPage,pageSize,accident);
        Map map = new HashMap();
        map.put("totalPage",page.getPages());
        map.put("page",page);
        return map;
    }

    @RequestMapping("/addAccident")
    public ModelAndView addAccident(Accident accident){
        ModelAndView mv = new ModelAndView();
        mv.setView(new MappingJackson2JsonView());
        returnOrderService.addAccident(accident);
        return mv;
    }

    public void setReturnOrderService(LQReturnOrderService returnOrderService) {
        this.returnOrderService = returnOrderService;
    }
}
